#pragma once
#include <string>

#include "../3rd/rapidjson/include/rapidjson/prettywriter.h"

template <typename T>
std::string Object2Json(T object) {
  rapidjson::StringBuffer sb;
  rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
  object.Serialize(writer);
  return sb.GetString();
}

std::string Qstring(std::string val) {
  if (val == "NULL") return val;
  return (std::string) "'" + val + "'";
}

std::string Qstring(int val) { return std::to_string(val); }

std::string FuzzyString(std::string str) { return "'%" + str + "%'"; };

std::string RawString(std::string str) {
  hassert(str.size() >= 2, "str.size() < 2");
  return str.substr(1, str.size() - 2);
}

std::string Concatenate(const std::vector<std::string>& strs) {
  bool first = true;
  std::string ret;
  for (const auto str : strs) {
    if (!first) {
      ret += "+";
    }
    ret += str;
    first = false;
  }
  return ret;
}

std::vector<std::string> Split(const std::string& str) {
  std::vector<std::string> ret;
  int pos = 0;
  while (str.find('+', pos) != std::string::npos) {
    auto p = str.find('+', pos);
    ret.push_back(str.substr(pos, p - pos));
    pos = p + 1;
  }
  ret.push_back(str.substr(pos));
  return ret;
}
